package com.example.administrator.yanfoxconn.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.activity.DNLookListActivity;
import com.example.administrator.yanfoxconn.activity.LMList2Activity;
import com.example.administrator.yanfoxconn.activity.LMListActivity;
import com.example.administrator.yanfoxconn.activity.LMMenuListActivity;
import com.example.administrator.yanfoxconn.bean.DNCheckMessage;
import com.example.administrator.yanfoxconn.bean.LMIE8S;

import java.util.List;

/**
 * LM IE8S 列表
 * Created by song on 2022/2/19.
 */

public class LMListAdapter extends BaseAdapter {
    private Context mContext;
    private LMListActivity lmListActivity;
    private LMList2Activity lmList2Activity;
    private LMMenuListActivity lmMenuListActivity;
    private List<LMIE8S> messageList;
    private String flag1,from="";



    public LMListAdapter(LMListActivity lmListActivity, List<LMIE8S> messageList, String flag1) {
        this.mContext = lmListActivity;
        this.messageList = messageList;
        this.flag1 = flag1;
    }
    public LMListAdapter(LMListActivity lmListActivity, List<LMIE8S> messageList, String flag1,String from) {
        this.mContext = lmListActivity;
        this.messageList = messageList;
        this.flag1 = flag1;
        this.from = from;
    }
    public LMListAdapter(LMList2Activity lmList2Activity, List<LMIE8S> messageList, String flag1,String from) {
        this.mContext = lmList2Activity;
        this.messageList = messageList;
        this.flag1 = flag1;
        this.from = from;
    }
    public LMListAdapter(LMMenuListActivity lmMenuListActivity, List<LMIE8S> messageList, String flag1) {
        this.mContext = lmMenuListActivity;
        this.messageList = messageList;
        this.flag1 = flag1;
    }


    @Override
    public int getCount() {
        return messageList.size();

    }

    @Override
    public Object getItem(int i) {
        return messageList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_lm_item, null);
            viewHolder.tvOne = convertView.findViewById(R.id.tv_one);
            viewHolder.tvTwo = convertView.findViewById(R.id.tv_two);
            viewHolder.tvThree = convertView.findViewById(R.id.tv_three);
            viewHolder.ll = convertView.findViewById(R.id.ll);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }

        if (flag1.equals("jcjh")){
            if (from.equals("")){
                viewHolder.tvOne.setText(messageList.get(position).getProduce_place());
            }else{
                viewHolder.tvOne.setText(messageList.get(position).getDepart());
            }
        if ((Integer.parseInt(messageList.get(position).getBeforeMonthWzg())+Integer.parseInt(messageList.get(position).getBeforeMonthYzg())-Integer.parseInt(messageList.get(position).getBeforeMonthYzg()))>0){
            viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_e84e4e));
        }else{
            viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_42D42B));
//            viewHolder.tvTwo.setText(messageList.get(position).getBeforeMonthYzg());
        }
        viewHolder.tvTwo.setText(messageList.get(position).getBeforeMonthWzg()+"/"+(Integer.parseInt(messageList.get(position).getBeforeMonthWzg())+Integer.parseInt(messageList.get(position).getBeforeMonthYzg())));

            if ((Integer.parseInt(messageList.get(position).getAfterMonthWzg())+Integer.parseInt(messageList.get(position).getAfterMonthYzg())-Integer.parseInt(messageList.get(position).getAfterMonthYzg()))>0){
                viewHolder.tvThree.setBackgroundColor(mContext.getResources().getColor(R.color.color_e84e4e));
           }else{
                viewHolder.tvThree.setBackgroundColor(mContext.getResources().getColor(R.color.color_42D42B));
//                viewHolder.tvThree.setText(messageList.get(position).getAfterMonthYzg());
            }
            viewHolder.tvThree.setText(messageList.get(position).getAfterMonthWzg()+"/"+(Integer.parseInt(messageList.get(position).getAfterMonthWzg())+Integer.parseInt(messageList.get(position).getAfterMonthYzg())));

        }else{
            viewHolder.ll.setGravity(Gravity.CENTER_VERTICAL);
            viewHolder.tvOne.setText(messageList.get(position).getType());
            if (from.equals("")){
                //季度稽核，季度列表
            if ((Integer.parseInt(messageList.get(position).getJdWzgNumberSum())+Integer.parseInt(messageList.get(position).getJdYzgNumberSum())-Integer.parseInt(messageList.get(position).getJdYzgNumberSum()))>0){
                viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_e84e4e));
                viewHolder.tvTwo.setText("有未整改");
            }else if(Integer.parseInt(messageList.get(position).getJdWzgNumberSum())==0&&Integer.parseInt(messageList.get(position).getJdYzgNumberSum())==0){
                viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_616161));
                viewHolder.tvTwo.setText("未開始");
            }else{
                viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_42D42B));
                viewHolder.tvTwo.setText("整改完成");
            }
            }else if(from.equals("one")){
                viewHolder.tvOne.setText(messageList.get(position).getProduce_place());
                if ((Integer.parseInt(messageList.get(position).getJdWzgNumber())+Integer.parseInt(messageList.get(position).getJdYzgNumber())-Integer.parseInt(messageList.get(position).getJdYzgNumber()))>0){
                    viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_e84e4e));
                }else{
                    viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_42D42B));
//                    viewHolder.tvTwo.setText(messageList.get(position).getJdYzgNumber());
                }
                viewHolder.tvTwo.setText(messageList.get(position).getJdWzgNumber()+"/"+(Integer.parseInt(messageList.get(position).getJdWzgNumber())+Integer.parseInt(messageList.get(position).getJdYzgNumber())));

            }else{
                viewHolder.tvOne.setText(messageList.get(position).getDepart());
                if ((Integer.parseInt(messageList.get(position).getJdWzgNumber())+Integer.parseInt(messageList.get(position).getJdYzgNumber())-Integer.parseInt(messageList.get(position).getJdYzgNumber()))>0){
                    viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_e84e4e));
                }else{
                    viewHolder.tvTwo.setBackgroundColor(mContext.getResources().getColor(R.color.color_42D42B));
//                    viewHolder.tvTwo.setText(messageList.get(position).getJdYzgNumber());
                }
                viewHolder.tvTwo.setText(messageList.get(position).getJdWzgNumber()+"/"+(Integer.parseInt(messageList.get(position).getJdWzgNumber())+Integer.parseInt(messageList.get(position).getJdYzgNumber())));

            }
            viewHolder.tvThree.setVisibility(View.GONE);
        }

        return convertView;
    }

    private class ViewHolder {
        public TextView tvOne,tvTwo, tvThree;
        public LinearLayout ll;
    }
}